package com.gobang;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.EnableRabbit;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.core.env.Environment;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * 五子棋在线对战平台 - 主启动类
 * 
 * @author Gobang Team
 * @version 1.0.0
 */
@Slf4j
@EnableRabbit
@SpringBootApplication
public class GobangApplication {

    public static void main(String[] args) {
        try {
            // 启动应用
            SpringApplication app = new SpringApplication(GobangApplication.class);
            Environment env = app.run(args).getEnvironment();
            
            // 获取服务器信息
            String protocol = "http";
            String serverPort = env.getProperty("server.port", "8080");
            String contextPath = env.getProperty("server.servlet.context-path", "/");
            String hostAddress = InetAddress.getLocalHost().getHostAddress();
            
            // 使用 SLF4J 日志输出启动信息
            log.info("\n====================================================================================================\n" +
                    "  应用启动成功！\n" +
                    "  应用名称：{}\n" +
                    "  活动环境：{}\n" +
                    "  本地访问：{}://localhost:{}{}\n" +
                    "  外部访问：{}://{}:{}{}\n" +
                    "  测试接口：{}://localhost:{}/hello\n" +
                    "====================================================================================================",
                    env.getProperty("spring.application.name"),
                    env.getProperty("spring.profiles.active"),
                    protocol,
                    serverPort,
                    contextPath,
                    protocol,
                    hostAddress,
                    serverPort,
                    contextPath,
                    protocol,
                    serverPort);
            
        } catch (UnknownHostException e) {
            log.error("启动时获取主机地址失败", e);
        }
    }

}

